/**
 * Created by IntelliJ IDEA.
 * User: amrk
 * Date: 12/02/2005
 * Time: 16:34:20
 * To change this template use File | Settings | File Templates.
 */
package com.talios.jira.browser;

import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.WindowManager;
import com.talios.jira.idea.JiraConfigurationComponent;

/**
 * @jira INTPLUG-170 Remove werx library and dependencies
 */
public class IssueManager {
    private static IssueManager ourInstance = new IssueManager();

    public static IssueManager getInstance() {
        return ourInstance;
    }

    /**
     * @jira INTPLUG-170 Remove werx library and dependencies
     */
    private IssueManager() {
    }

    /**
     * @jira INTPLUG-170 Remove werx library and dependencies
     */
    public void stopWorkingOnIssues(Project project) {
        JiraConfigurationComponent config = project.getComponent(JiraConfigurationComponent.class);
        JiraItem item = config.getItemWorkedOn();
        if (item != null) {
            WindowManager.getInstance().getStatusBar(project).setInfo("No longer working on issue " + item.getKey() + ": " + item.getTitle());
            item.stopWorkingOnIssue();
        }
    }

    /**
     * @jira INTPLUG-170 Remove werx library and dependencies
     */
    public void startWorkOnIssue(Project project, JiraItem item) {

        JiraConfigurationComponent config = project.getComponent(JiraConfigurationComponent.class);
        JiraItem oldItem = config.getItemWorkedOn();

        config.setItemWorkedOn(item);
        if (item != null) {
            WindowManager.getInstance().getStatusBar(project).setInfo("Now working on issue " + item.getKey() + ": " + item.getTitle());
            item.startWorkingOnIssue();
        } else {
            if (oldItem != null) {
                WindowManager.getInstance().getStatusBar(project).setInfo("No longer working on issue " + oldItem.getKey() + ": " + oldItem.getTitle());
                oldItem.stopWorkingOnIssue();
            }
        }

    }
}
